package com.bw.i_video.startup

import android.util.Log
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.LiveData

/**
 * 启动优化管理器
 * 负责协调冷启动完成和倒计时开始的时序
 */
object StartupOptimizationManager {
    
    private const val TAG = "StartupOptimizationManager"
    
    // 使用LiveData来通知启动优化完成
    private val _optimizationComplete = MutableLiveData<StartupOptimizationCompleteEvent>()
    val optimizationComplete: LiveData<StartupOptimizationCompleteEvent> = _optimizationComplete
    
    // 启动优化状态
    private var isOptimizationComplete = false
    private var optimizationEvent: StartupOptimizationCompleteEvent? = null
    
    /**
     * 通知启动优化完成
     */
    fun notifyOptimizationComplete(optimizationTime: Long, taskCount: Int, isSuccess: Boolean = true) {
        val event = StartupOptimizationCompleteEvent(optimizationTime, taskCount, isSuccess)
        Log.d(TAG, "启动优化完成，通知开始倒计时: $event")
        
        isOptimizationComplete = true
        optimizationEvent = event
        _optimizationComplete.postValue(event)
    }
    
    /**
     * 检查启动优化是否完成
     */
    fun isOptimizationComplete(): Boolean {
        return isOptimizationComplete
    }
    
    /**
     * 重置状态（用于测试）
     */
    fun reset() {
        isOptimizationComplete = false
        optimizationEvent = null
        _optimizationComplete.value = null
    }
}
